package com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.dao.RatingItemsDao;
import com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.entity.RatingItemsInfo;
import com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.entity.SearchRatingItemsInfo;
import com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.service.IRatingItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class RatingItemsServiceImpl implements IRatingItemsService {
    @Autowired
    private RatingItemsDao dao;

    @Autowired
    private SqlMapper sqlMapper;

    @Override
    public List<RatingItemsInfo> selectPageListByQueryGetMap(Page<RatingItemsInfo> page, SearchRatingItemsInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getRatingItems())) {
            params.put("ratingItems", searchInfo.getRatingItems());
        }
        return dao.getQueryPage(page, params);
    }

    public RatingItemsInfo selectOneById(String ratingItemsId) {
        String sql = "select * from rating_items_info where id= '" + ratingItemsId + "'";
        RatingItemsInfo info = sqlMapper.selectOne(sql, RatingItemsInfo.class);
        return info;
    }

    public int insert(RatingItemsInfo info) {
        String sql = "INSERT INTO `rating_items_info` (`rating_items`, `remarks`, `num`) VALUES" +
                "('" + info.getRatingItems().trim() + "','" + info.getRemarks().trim() + "'," + info.getNum() + ");";
        return sqlMapper.insert(sql);
    }

    @Transactional
    public void delete(String id) {
        String sql = "delete from rating_items_info where id = '" + id + "'";
        sqlMapper.delete(sql);
    }

    public int update(RatingItemsInfo info) {
        return dao.updateById(info);
    }

    public List<Map<String, Object>> list() {
        String sql = "select id, ratingItems from rating_items_info order by num asc;";
        return sqlMapper.selectList(sql);
    }
}